package com.caigp.cookbook2.application;

import android.app.Application;
import android.widget.Toast;

import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.beta.upgrade.UpgradeStateListener;

import org.litepal.LitePal;

public class CookBookApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        //初始化litepal
        initLitePal();
        //初始化bugly
        initBugly();
    }

    private void initBugly() {
        Beta.autoInit = true;
        Beta.autoCheckUpgrade = false;
        /* 设置更新状态回调接口 */
        Beta.upgradeStateListener = new UpgradeStateListener() {
            @Override
            public void onUpgradeSuccess(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_SUCCESS",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onUpgradeFailed(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_FAILED",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onUpgrading(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_CHECKING",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDownloadCompleted(boolean b) {

            }

            @Override
            public void onUpgradeNoVersion(boolean isManual) {
                Toast.makeText(CookBookApplication.this,"没有新版本",Toast.LENGTH_SHORT).show();
            }
        };
        Bugly.init(CookBookApplication.this, "fc3c2a3302", false);
    }

    private void initLitePal() {
        LitePal.initialize(this);
    }
}
